home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / EMIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.7 KB  |  59 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <dos.h>
  4. #define BIOS_VIDEO 0x10
  5. void interrupt vio_handler(void);
  6. void interrupt (*old_handler)(void);
  7. void chain_int(void interrupt (*p_func)());
  8. main()
  9. {
  10.     union REGS xr, yr;
  11.     int c;
  12. /* Install kthe new handler named vio_handler
  13.  * Disable interrupts when changing handler */
  14.     disable();
  15.     old_handler =getvect(BIOS_VIDEO);
  16.     setvect(BIOS_VIDEO,vio_handler);
  17.     enable();
  18. /* Print out address of old handler using %p format */
  19.     printf("\nThe address of the old handler is: "
  20.         "%Fp\n", old_handler);
  21.     printf("Installed new handler: %Fp\n", vio_handler);
  22.  
  23. /* Do some video I/O --change cursor to a solid block */
  24.     xr.h.ah =1;
  25.     xr.h.ch =0;
  26.     xr.h.cl =8;
  27.     int86(BIOS_VIDEO, &xr, &yr);
  28. /* Quit when user says so */
  29.     printf("Hit q to quit: ");
  30.     while( (c = getch() ) != 'q');  /* Keep looping till 'q' */
  31. /* Reset vector. Disable interrupts when doing this   */
  32.     disable();
  33.     setvect(BIOS_VIDEO, old_handler);
  34.     enable();
  35. }
  36. /* ----------------------------------------------------------- */
  37. void interrupt vio_handler(void)
  38. {
  39. /* Our handler simply chains to the old_handler using
  40.  * chain_int (see below) */
  41.     chain_int(old_handler);
  42. }
  43. /* ------------------------------------------------------------ */
  44. void chain_int(void(interrupt *p_func)())
  45. {
  46. /* Embed machine code to properly call an interrupt
  47.  * handler by using the library routine __emit__.
  48.  * Note that Turbo C would have generated
  49.  * correct code (push flags, then call handler) even
  50.  * if we had invoked the old handler with the usual
  51.  * (*old_handler)(),but we wanted to show how
  52.  * __emit__works.
  53.  */
  54.  /* PUSHF */
  55.     __emit__((unsigned char)0x9c);
  56. /* CALL FAR [BP+4] */
  57.     __emit__((unsigned char)0xff, 0x5e, &p_func);
  58. }
  59.